/// author stevenHu
///
/// created by hujintao
/// created at 2021/9/13
import 'dart:ui' as ui show window;

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

/// 屏幕字体适配
class Adapter {
  /// 设置宽度
  static double setWidth(double size) {
    return ScreenUtil().setWidth(size);
  }

  /// 设置高度
  static double setHeight(double size) {
    return ScreenUtil().setHeight(size);
  }

  /// 设置字体
  static double setSp(double size) {
    return ScreenUtil().setSp(size);
  }

  /// 更新状态栏样式
  static updateStatusBarStyle(SystemUiOverlayStyle style) {
    SystemChrome.setSystemUIOverlayStyle(style);
  }

  /// 屏幕宽度
  static double get width {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.size.width;
  }

  /// 屏幕高度
  static double get height {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.size.height;
  }

  /// 屏幕比例
  static double get scale {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.devicePixelRatio;
  }

  /// 字体大小倍率
  static double get textScaleFactor {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.textScaleFactor;
  }

  /// 导航条高度
  static double get navigationBarHeight {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.padding.top + kToolbarHeight;
  }

  /// 顶部安全区域高度
  static double get topSafeHeight {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.padding.top;
  }

  /// 底部安全区域高度
  static double get bottomSafeHeight {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.padding.bottom;
  }
}

///屏幕适配 - 点语法
// extension HkScreenAdapter on num {
//   num get w {
//     if (kIsWeb == false) {
//       if (Platform.isIOS) return toDouble();
//     }
//     return (ScreenUtil().scaleWidth * this).toDouble();
//   }
// }
